﻿#if NETFX_CORE
using Windows.UI.Xaml.Controls;

namespace Nx.Commands
{
    /// <summary>
    /// This behavior enables the ItemClick event and executes the command whenever the ItemClick event is raised. 
    /// Can only be applied to controls which derive from ListViewBase
    /// </summary>
    public class ListViewBaseItemClickBehavior : CommandBehaviorBase<ListViewBase>
    {
        public ListViewBaseItemClickBehavior(ListViewBase itemObject)
            : base(itemObject)
        {
            if (!itemObject.IsItemClickEnabled)
            {
                itemObject.IsItemClickEnabled = true;
            }

            itemObject.ItemClick += OnItemClick;
        }

        private void OnItemClick(object sender, ItemClickEventArgs e)
        {
            this.CommandParameter = e.ClickedItem;
            ExecuteCommand();
        }
    }
}
#endif